<?php
/**
 * Created by PhpStorm.
 * User: Mio
 * Date: 2017/10/13
 * Time: 17:19
 */

namespace app\index\model;



use think\Model;

class Post extends Model
{

    //添加帖子
    public function addPost($arr){
//        var_dump($arr);
        if(!is_array($arr)) return false;
//        var_dump(11);

        $arr['addtime'] = time();
        $arr['praise_num'] = 0;
        $arr['collect_num'] = 0;
        $arr['comment_num'] = 0;
        $arr['updatetime'] = $arr['addtime'];
        $imgs = $arr['imgs'];
//        var_dump($imgs);
//        unset($arr['imgs']);
        $r = $this->insertGetId($arr);
        //发帖成功加经验
        if($r){
            if($imgs){
                //添加图片
                $imgs = explode(',', $imgs);
                $img_arr = array();
                foreach ($imgs as $k => $v) {
                    $img_arr[$k]['post_id'] = $r;
                    $img_arr[$k]['img_url'] = $v;
                }
                model('PostImg')->addPostImg($img_arr);
            }
            $post_exp = model('Config')->getConfig('post_exp_num');
            model('UserChannelRank')->addExp($arr['user_id'], $arr['channel_id'], $post_exp);
        }
        return $r;
    }
}